<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <title>Register</title>
<%--    简单的验证函数--%>
    <script type="text/javascript">
        function validate_uesname_null(name) {
            return !(name.value == null || name.value === "");
        }

        function validate_uesname_number(onechar) {
            return !(onechar.value >= "0" && onechar.value <= "9");
        }

        function validate_uesname_length(name) {
            return name.value.length >= 6 && name.value.length <= 20;
        }

        function validate_possword_null(pwd) {
            return !(pwd.value == null || pwd.value === "");
        }

        function validate_repossword(pwd, repwd) {
            return repwd.value === pwd.value;
        }

        function validate_possword_length(pwd) {
            return pwd.value.length >= 6 && pwd.value.length <= 20;
        }

        function validate_posswordAnduesname(pwd, name) {
            return pwd.value !== name.value;
        }

        function validate_email_null(email) {
            return !(email.value == null || email.value === "");
        }

        function validate_email_format(email) {
            const apos = email.value.indexOf("@");
            if (apos === "-1") {
                return false;
            }
            const dotpos = email.value.lastIndexOf(".");
            return dotpos - apos >= 2;

        }

        function a1() {
            const name = document.getElementById("uesname");
            const pwd = document.getElementById("pwd");
            const repwd = document.getElementById("repwd");
            const email = document.getElementById("email");
            let int = "出现以下错误:";
            if (!validate_uesname_null(name)) {
                int = int + "\n  用户名不能为空";
            } else {
                if (!validate_uesname_number(name.value.charAt(0))) {
                    int = int + "\n  用户名不能以数字开头";
                } else {
                    if (!validate_uesname_length(name)) {
                        int = int + "\n  用户名长度应6字符~20字符";
                    }
                }
            }
            if (!validate_possword_null(pwd)) {
                int = int + "\n  密码不能为空";
            } else {
                if (!validate_repossword(pwd, repwd)) {
                    int = int + "\n  再次输入密码不一致";
                } else {
                    if (!validate_possword_length(pwd)) {
                        int = int + "\n  密码长度应6字符~20字符";
                    } else {
                        if (!validate_posswordAnduesname(pwd, name)) {
                            int = int + "\n  密码不能与用户名相同";
                        }
                    }
                }
            }
            if (!validate_email_null(email)) {
                int = int + "\n  邮箱不能为空";
            } else {
                if (!validate_email_format(email)) {
                    int = int + "\n  邮箱错误格式 例：123456789@123.com";
                }
            }/**/
            alert(int);

        }
    </script>
</head>
<body>
<%--      onsubmit="return a1()"--%>
<form action="${pageContext.request.contextPath}/loginService/Register" method="post">
    <p>
        <label for="username">用户名：</label>
        <input type="text" name="username" id="username">
    </p>
    <p>
        <label for="TorE">电话或邮箱：</label>
        <input type="text" name="TorE" id="TorE">
    </p>
    <p>
        <label for="password">密码：</label>
        <input type="password" name="password" id="password">
    </p>
    <p>
        <label for="repassword">再次确认密码：</label>
        <input type="password" name="repassword" id="repassword">
    </p>
    <input type="submit" value="确定">
    <input type="reset" value="重置">
</form>

</body>
</html>